<? Phpr_View::beginBlock("head") ?>
	<script type="text/javascript" src="modules/cms/resources/javascript/edit.js?<?= module_build('cms') ?>"></script>
	<script type="text/javascript" src="modules/cms/resources/javascript/splitpanel.js"></script>
	<script type="text/javascript" src="modules/cms/resources/javascript/cms_object.js"></script>
	
	<? if (!isset($fatalError) && $form_model && !$form_model->file_is_missing()): ?>
		<script type="text/javascript" src="modules/backend/resources/javascript/unload_manager.js"></script>
		<script type="text/javascript">
			UnloadManager.unload_message = 'The template content has been changed. Unsaved data will be lost.';
			
			update_browser_title_active = true;
			update_browser_title_field = 'Cms_Template_name';
			update_browser_title_text = 'Edit Template';	
		</script>
	<? endif ?>
<? Phpr_View::endBlock() ?>

<? Phpr_View::beginBlock("view") ?>
	<ul class="breadcrumbs">
		<li><a href="<?= url('/cms/templates') ?>">Templates</a></li>
		<li><?= $this->app_page_title ?></li>
	</ul>

	<? if (!isset($fatalError)): ?>
		<div id="template_info"><? $this->renderPartial('template_info') ?></div>
	<? endif ?>
	
	<? if (!isset($fatalError)): ?>
		<? if (!($lock = Db_RecordLock::lock_exists($form_model))): ?>
			<? if (!$form_model->file_is_missing()): ?>
				<div>
					<table class="layoutTable">
						<tr>
							<td>
								<?= Phpr_Form::openTag(array('id'=>'form_element')) ?>
									<? $this->formRender() ?>

									<?= backend_ajax_button('<u>S</u>ave', 'edit_onSave', array(), "prepareFunction: function(){phprTriggerSave();}, extraFields: {redirect: 0}, loadIndicator: {show: false}, onBeforePost: LightLoadingIndicator.show.pass('Saving...'), onSuccess: function(){UnloadManager.reset_changes()}, onComplete: LightLoadingIndicator.hide, update: 'multi'") ?>
									<?= backend_ajax_button('Save and Close', 'edit_onSave', array(), "prepareFunction: function(){phprTriggerSave();}, onBeforeScriptEval: function(){UnloadManager.reset_changes()}") ?>
									<?= backend_ajax_button('Close', 'edit_onCancel', array(), "onBeforeScriptEval: function(){UnloadManager.reset_changes()}") ?>

									<?= backend_ajax_button('Delete', 'edit_onDelete', array('class'=>"right"), "confirm: 'Do you really want to delete this template?', onBeforeScriptEval: function(){UnloadManager.reset_changes()}") ?>
									<div class="clear"></div>
								</form>
								<? $this->formAddLockCode() ?>
							</td>
							<td class="rightFixedColumn secondary_tabs">
								<? $this->renderPartial(PATH_APP.'/modules/cms/controllers/partials/_sidebar.htm') ?>
							</td>
						</tr>
					</table>
				</div>
			<? else: ?>
				<? $this->renderPartial('fix_template_file') ?>
			<? endif ?>
		<? else: ?>
			<? $this->renderPartial(PATH_APP.'/modules/backend/controllers/partials/_record_locked.htm', array(
				'record_name'=>'template',
				'lock'=>$lock
			)) ?>
		<? endif ?>
	<? else: ?>
		<?= flash() ?>

		<p><a href="<?= url('/cms/templates') ?>">Return to the template list</a></p>
	<? endif ?>
<? Phpr_View::endBlock() ?>